<?php

function pwdHash($username, $salt, $password) {
    
    $len = strlen($username);
    if ($len > 40) {
        $len = $len % 40;
    }
    $aftersalt = substr($salt, 0, $len);
    $afterpassword = sha1($password.$aftersalt);
    return $afterpassword;
}

function getClientIp() {
    
    $unknow = 'unknow';
    if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])
        && $_SERVER['HTTP_X_FORWARDED_FOR']
        && strcasecmp($_SERVER['HTTP_X_FORWARDED_FOR'], $unknow)) {
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    } elseif (isset($_SERVER['REMOTE_ADDR'])
        && $_SERVER['REMOTE_ADDR']
        && strcasecmp($_SERVER['REMOTE_ADDR'], $unknow)) {
        $ip = $_SERVER['REMOTE_ADDR'];
    }

    return $ip;
}

function isLogin() {
    
    if (isset($_SESSION['logined']) && $_SESSION['logined'] == true) {
        return true;
    } else {
        return false;
    }
}
